<%@ page language="java" import="java.util.*,com.example.filemanagement.*" pageEncoding="utf-8"%>
<html>
<body>
<%
        request.setCharacterEncoding("utf-8");
        String SendName = request.getParameter("SendName");
        String SendNumber = request.getParameter("SendNumber");
        String SendMajor = request.getParameter("SendMajor");
        String SendGender = request.getParameter("SendGender");
        String Sendage = request.getParameter("Sendage");
        String SendGrade = request.getParameter("SendGrade");
        String Sendbanji = request.getParameter("Sendbanji");
        if(!Connect.vd(SendName)){
            request.setAttribute("msg", "填写失败，姓名只能用汉字");
            request.getRequestDispatcher("addinfomation.jsp").forward(request, response);
        } else if (!Connect.vd(SendMajor)) {
            request.setAttribute("msg", "填写失败，专业只能用汉字");
            request.getRequestDispatcher("addinfomation.jsp").forward(request, response);
        }else if(!(SendGender.equals("男")||SendGender.equals("女"))){
            request.setAttribute("msg", "填写失败，性别只能填男或者女");
            request.getRequestDispatcher("addinfomation.jsp").forward(request, response);
        } else if (!Connect.isNumeric(Sendage)) {
            request.setAttribute("msg", "填写失败，年龄只能用数字");
            request.getRequestDispatcher("addinfomation.jsp").forward(request, response);
        } else if (!Connect.isNumeric(SendGrade)) {
            request.setAttribute("msg", "填写失败，年级只能用数字");
            request.getRequestDispatcher("addinfomation.jsp").forward(request, response);
        } else if (!Connect.isNumeric(Sendbanji)) {
            request.setAttribute("msg", "填写失败，班级只能用数字");
            request.getRequestDispatcher("addinfomation.jsp").forward(request, response);
        }else {

            if (SendNumber.equals(session.getAttribute("LoginedUserName"))) {
                int SendResult = Connect.Insert(SendNumber, SendMajor, SendGender, Sendage, SendGrade, Sendbanji);
                if (SendResult == -1) {
                    request.setAttribute("msg", "填写失败，您的信息不能有空项");
                    request.getRequestDispatcher("addinfomation.jsp").forward(request, response);
                }
                if (SendResult == 1) {
                    request.setAttribute("msg", "填写成功！");
                    request.getRequestDispatcher("index.jsp").forward(request, response);
                }
            } else {
                request.setAttribute("msg", "填写失败，学号填写错误");
                request.getRequestDispatcher("addinfomation.jsp").forward(request, response);
            }
        }
%>
</body>
</html>
